/*
 *  Copyright (C) 2011 JiangHongTiao <jjurco.sk_gmail.com>
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package sk.lieskove301.jianghongtiao.liaad.prisoner.memory;

import java.util.Deque;
import sk.lieskove301.jianghongtiao.liaad.prisoner.strategy.FightResultEnum;

/**
 * Date of create: May 15, 2011
 *
 * @author JiangHongTiao <jjurco.sk_gmail.com>
 * @version 2011.0515
 */
public class RememberAndForget extends AbstractForgetting implements Forgetting{

    private double OFI = 0.5;
    private double STAB = 5;

    /**
     * <h4>Optimal Forgetting Index (OFI)</h4>
     * How do I remember the Fact? I have to remind myself of it before I forget.
     * Using the implemented definition of RET, one can say: I will remind myself
     * of the fact before its RET drops under a certain level. Let’s call the RET
     * volume we admit to losing the Optimal Forgetting Index (OFI). Knowing the
     * dependency of the RET on time, I can calculate from the appropriate OFI the
     * next time I need to repeat the Fact This is the basic idea for the generalization
     * of the simple advice “review after 1, 2, 4… days”.
     * <br><br>
     * RET = 1/2^(m/STAB)
     * @param OFI index of forgetting
     * @param STAB Stability (STAB) - Retrievability decreases over time. In the
     * language of the newly established terms, we say that we are forgetting.
     * The Stability is a parameter which says how quickly the Retrievability
     * disappears. The Stability can be increased by a suitable repetition of
     * the Fact. That is the goal of learning.
     */
    public RememberAndForget(double OFI, double STAB) {
        this.OFI = OFI;
        this.STAB = STAB;
    }

    public RememberAndForget() {
    }

    public FightResultEnum countBetrayMemories(Deque<FightResultEnum> memory) {
        boolean my = Math.pow(0.5, countLastBetray(memory, true, 0)/STAB) < 1 - OFI;
        boolean him = Math.pow(0.5, countLastBetray(memory, false, 0)/STAB) < 1 - OFI;
        return countByResults(my, him);
    }

    public FightResultEnum countCooperateMemories(Deque<FightResultEnum> memory) {
        boolean my = Math.pow(0.5, countLastCooperation(memory, true, 0)/STAB) < 1 - OFI;
        boolean him = Math.pow(0.5, countLastCooperation(memory, false, 0)/STAB) < 1 - OFI;
        return countByResults(my, him);
    }

    public String getName() {
        return "Remember And Forget";
    }

    public String getLetter() {
        return "F";
    }
}
